//Luogu:392844 the second year in CSP-S rp++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,af[200001],a[200001],c[200001],x,T,t[11],ans;
unordered_map<ll,unordered_map<ll,bool> > d;
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(ll i=1;i<=n;i++) scanf("%lld",af+i);
    for(ll i=1;i<=m;i++) scanf("%lld",c+i);
    k=__lg(n);if(1<<k < n) k++;
    for(ll i=k-1;i>=0;i--){
        for(ll j=1;j<=1<<i;j++){
            char c;
            c=getchar();
            while(c!='0' && c!='1') c=getchar();
            d[k-i][j]=c-'0';
        }
    }
    scanf("%lld",&T);
    T=1;
    while(T--){
        ans=0;
        scanf("%lld %lld %lld %lld",t+0,t+1,t+2,t+3);
        for(ll i=1;i<=n;i++) a[i]=af[i] ^ t[i%4];
        vector<ll> players,wins,re;
        for(ll pl=1;pl<=m;pl++){
            ll winner=0;
            players.clear();
            wins.clear();
            for(ll i=1;i<=c[pl];i++) players.push_back(i);
            for(ll i=1;i<=__lg(c[pl])+1;i++){
                for(ll j=0;j<players.size();j+=2){
                    if(!d[i][j/2+1]){
                        if(a[players[j]]>=i) wins.push_back(players[j]);
                        else wins.push_back(players[j+1]);
                    }
                    else{
                        if(a[players[j+1]]>=i) wins.push_back(players[j+1]);
                        else wins.push_back(players[j]);
                    }
                }
                winner=players[0];
                players.clear();
                for(auto&&j:wins) players.push_back(j);
                wins.clear();
            }
            ans=(ans) ^ (pl*winner);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
/*
16:27 finish reading
The problem is TOO long, I have to say. trying to solve when T==1
17:19 finished A maybe less than 8 pts.
*/
